Make FormatMetadata accept RequestContext, instead of hard coding $wgLang.
[lhc/web/wiklou.git] / tests / phpunit / includes / media / FormatMetadataTest.php
1 <?php
2 class FormatMetadataTest extends MediaWikiTestCase {
3
4 protected function setUp() {
5 parent::setUp();
6
7 if ( !extension_loaded( 'exif' ) ) {
8 $this->markTestSkipped( "This test needs the exif extension." );
9 }
10 $filePath = __DIR__ . '/../../data/media';
11 $this->backend = new FSFileBackend( array(
12 'name' => 'localtesting',
13 'lockManager' => 'nullLockManager',
14 'containerPaths' => array( 'data' => $filePath )
15 ) );
16 $this->repo = new FSRepo( array(
17 'name' => 'temp',
18 'url' => 'http://localhost/thumbtest',
19 'backend' => $this->backend
20 ) );
21
22 $this->setMwGlobals( 'wgShowEXIF', true );
23 }
24
25 public function testInvalidDate() {
26 $file = $this->dataFile( 'broken_exif_date.jpg', 'image/jpeg' );
27
28 // Throws an error if bug hit
29 $meta = $file->formatMetadata();
30 $this->assertNotEquals( false, $meta, 'Valid metadata extracted' );
31
32 // Find date exif entry
33 $this->assertArrayHasKey( 'visible', $meta );
34 $dateIndex = null;
35 foreach ( $meta['visible'] as $i => $data ) {
36 if ( $data['id'] == 'exif-datetimeoriginal' ) {
37 $dateIndex = $i;
38 }
39 }
40 $this->assertNotNull( $dateIndex, 'Date entry exists in metadata' );
41 $this->assertEquals( '0000:01:00 00:02:27',
42 $meta['visible'][$dateIndex]['value'],
43 'File with invalid date metadata (bug 29471)' );
44 }
45
46 /**
47 * @param $filename String
48 * @param $expected Integer Total image area
49 * @dataProvider provideFlattenArray
50 * @covers FormatMetadata::flattenArray
51 */
52 public function testFlattenArray( $vals, $type, $noHtml, $ctx, $expected ) {
53 $actual = FormatMetadata::flattenArray( $vals, $type, $noHtml, $ctx );
54 $this->assertEquals( $expected, $actual );
55 }
56
57 public static function provideFlattenArray() {
58 return array(
59 array (
60 array(1 ,2 ,3), 'ul', false, false,
61 "<ul><li>1</li>\n<li>2</li>\n<li>3</li></ul>",
62 ),
63 array (
64 array(1 ,2 ,3), 'ol', false, false,
65 "<ol><li>1</li>\n<li>2</li>\n<li>3</li></ol>",
66 ),
67 array (
68 array(1 ,2 ,3), 'ul', true, false,
69 "\n*1\n*2\n*3",
70 ),
71 array (
72 array(1 ,2 ,3), 'ol', true, false,
73 "\n#1\n#2\n#3",
74 ),
75 // TODO: more test cases
76 );
77 }
78
79 private function dataFile( $name, $type ) {
80 return new UnregisteredLocalFile( false, $this->repo,
81 "mwstore://localtesting/data/$name", $type );
82 }
83 }